package day12;

import cn.hutool.core.io.IoUtil;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Random;

import static day12.homework02.insertnames;

public class homework03 {
    public static void main(String[] args) throws Exception {
        BufferedReader reader1= IoUtil.getReader(new FileReader("womannames.txt"));
        BufferedReader reader2=IoUtil.getReader(new FileReader("mannames.txt"));
        ArrayList<String> names=insertnames(reader1,reader2);
        reader2.close();
        reader1.close();
        callname(names,100000);
    }

    private static void callname(ArrayList<String> names, int num) {
        int mansnum=0;
        int womansnum=0;
        int nums=0;
        int m=0;
        int wom=0;
        S:while (true){
            if(nums==num){
                break S;
            }
            if(mansnum==7&&womansnum==3){
                mansnum=0;
                womansnum=0;
            }
            String s=named(names);
            if (s.contains("男")){
                if(mansnum>=7){
                    continue S;
                }
                mansnum++;
                System.out.println(s);
                m++;
                nums++;
            } else if (s.contains("女")) {
                if(womansnum>=3){
                    continue S;
                }
                womansnum++;
                System.out.println(s);
                nums++;
                wom++;
            }
        }
        System.out.println("一共"+m+"个男生,"+wom+"个女生");
    }

    public static String named(ArrayList<String> names) {
        Random rm=new Random();
        int numbering=rm.nextInt(names.size());
        return names.get(numbering);
    }
}
